package cn.org.xwb.bookmall.model.utils;

import cn.hutool.core.date.DateUtil;
import cn.org.xwb.bookmall.model.properties.AccountProp;
import cn.org.xwb.common.utils.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class AccountUtil {

    @Autowired
    private AccountProp accountProp;

    /**
     * 生成账号
     *
     * @return
     */
    public String genAccount() {
        StringBuilder newAccount = new StringBuilder();
        newAccount
                .append(accountProp.getAccountPrefix())
                .append(DateUtil.format(new Date(), accountProp.getAccountFormat()))
                .append(RandomUtil.genRandNumStr(accountProp.getAccountSuffixLength()));
        return newAccount.toString();
    }

}
